package com.techina.android;

import android.app.Activity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

public class Techina extends Activity {
        private TextView textView;

        private CheckBox checkBox1;
        private CheckBox checkBox2;
        private CheckBox checkBox3;
        private CheckBox checkBox4;
        private CheckBox checkBox5;

        private Button button;

        @Override
        protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.main);

                textView = (TextView) findViewById(R.id.TextView01);

                checkBox1 = (CheckBox) findViewById(R.id.CheckBox01);
                checkBox2 = (CheckBox) findViewById(R.id.CheckBox02);
                checkBox3 = (CheckBox) findViewById(R.id.CheckBox03);
                checkBox4 = (CheckBox) findViewById(R.id.CheckBox04);
                checkBox5 = (CheckBox) findViewById(R.id.CheckBox05);
                button = (Button) findViewById(R.id.button1);

                checkBox1
                                .setOnCheckedChangeListener(new CheckBox.OnCheckedChangeListener() {

                                        @Override
                                        public void onCheckedChanged(CompoundButton buttonView,
                                                        boolean isChecked) {
                                                if (checkBox1.isChecked()) {
                                                        DisplayToast("不会吧？MM也能用帅来形容？!");
                                                }
                                        }
                                });
                checkBox2
                                .setOnCheckedChangeListener(new CheckBox.OnCheckedChangeListener() {

                                        @Override
                                        public void onCheckedChanged(CompoundButton buttonView,
                                                        boolean isChecked) {
                                                if (checkBox2.isChecked()) {
                                                        DisplayToast("算你有眼光！");
                                                }
                                        }
                                });
                checkBox3
                                .setOnCheckedChangeListener(new CheckBox.OnCheckedChangeListener() {

                                        @Override
                                        public void onCheckedChanged(CompoundButton buttonView,
                                                        boolean isChecked) {
                                                if (checkBox3.isChecked()) {
                                                        DisplayToast("你好友品味啊！让" + checkBox1.getText()+"请你吃金钱豹！");
                                                }
                                        }
                                });
                checkBox4
                                .setOnCheckedChangeListener(new CheckBox.OnCheckedChangeListener() {

                                        @Override
                                        public void onCheckedChanged(CompoundButton buttonView,
                                                        boolean isChecked) {
                                                if (checkBox4.isChecked()) {
                                                        DisplayToast(checkBox4.getText()+"可是百度的许文强啊！");
                                                }
                                        }
                                });
                checkBox5
                .setOnCheckedChangeListener(new CheckBox.OnCheckedChangeListener() {

                        @Override
                        public void onCheckedChanged(CompoundButton buttonView,
                                        boolean isChecked) {
                                if (checkBox5.isChecked()) {
                                        DisplayToast("你选择了：" + checkBox5.getText());
                                }
                        }
                });
                button.setOnClickListener(new Button.OnClickListener() {

                        @Override
                        public void onClick(View v) {
                                int num = 0;
                                if (checkBox1.isChecked()) {
                                        num++;
                                }
                                if (checkBox2.isChecked()) {
                                        num++;
                                }
                                if (checkBox3.isChecked()) {
                                        num++;
                                }
                                if (checkBox4.isChecked()) {
                                        num++;
                                }
                                if (checkBox5.isChecked()) {
                                        num++;
                                }
                                DisplayToast("你一共选择了：" + num + "个人");
                        }
                });
        }

        public void DisplayToast(String str) {
                Toast toast = Toast.makeText(getApplicationContext(), str,
                                Toast.LENGTH_LONG);
                toast.setGravity(Gravity.CENTER, 0, 0);
                LinearLayout toastView = (LinearLayout) toast.getView();
                ImageView imageCodeProject = new ImageView(getApplicationContext());
                imageCodeProject.setImageResource(R.drawable.icon);
                toastView.addView(imageCodeProject, 0);
                toast.show();
                /*
                 * Toast toast=Toast.makeText(this, str, Toast.LENGTH_SHORT);
                 * toast.setGravity(Gravity.TOP, 0, 220); toast.show();
                 */
        }

}